// Simple and fast function for regexp based param extraction
String.prototype.getURIParam = function(param) {
	var uriRe = new RegExp('[\?&;]?(' + param + '\=)([^&]*)', 'g'),
		parse, 
		result = [];

	while ((parse = uriRe.exec(this)) != null)
		result.push(decodeURIComponent(parse[2].replace('+', ' ')));

	return result;
};

function loadAndExecuteScript(url, callback){
	var script = document.createElement('script');
	script.type = "text/javascript";
	document.body.appendChild(script);	

	script.type = "text/javascript";

	if (script.readyState){	 //IE
		script.onreadystatechange = function(){
			if (script.readyState == "loaded" ||
					script.readyState == "complete"){
				script.onreadystatechange = null;
				callback();
			}
		};
	} else {  //Others
		script.onload = function(){
			callback();
		};
	}

	script.src = url;
}


window.onload = function() {
	var country = location.search.getURIParam('map').pop() || 'ua', container;
	if (!country.match(/^[a-z]{2}$/))
		country = 'ua';
	
	container = document.getElementById('map');
	if (!container)
		return;
		
	container.innerHTML = 'Loading&hellip;';
	
	loadAndExecuteScript('../maps/' + country + '.js', function() {
		container.innerHTML = '';
		var map = SVGMap(container, mapdata, {onClick: function(id) {
			alert(id);
		}});
	});
}